package com.atguigu.tingshu.album.config;

import com.atguigu.tingshu.common.constant.RabbitConstant;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AlbumIndexMQConfig {

    @Bean
    public Exchange exchange(){
        return ExchangeBuilder.directExchange(RabbitConstant.SEARCH_EXCHANGE).build();
    }

    @Bean
    public Queue upperAlbumQueue(){
        return QueueBuilder.durable(RabbitConstant.SEARCH_UPPER_QUEUE).build();
    }

    @Bean
    public Queue lowerAlbumQueue(){
        return QueueBuilder.durable(RabbitConstant.SEARCH_LOWER_QUEUE).build();
    }

    @Bean
    public Binding bindingUpperAlbum(){
        return BindingBuilder.bind(upperAlbumQueue()).to(exchange()).with(RabbitConstant.SEARCH_UPPER_QUEUE_KEY).noargs();
    }

    @Bean
    public Binding bindingLowerAlbum(){
        return BindingBuilder.bind(lowerAlbumQueue()).to(exchange()).with(RabbitConstant.SEARCH_LOWER_QUEUE_KEY).noargs();
    }
}
